<?php

/*    This file is part of ipmanage.

    ipmanage is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ipmanage is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ipmanage.  If not, see <http://www.gnu.org/licenses/>.
*/

// GET args
$mode=urldecode($_GET['mode']);

// Load configuration if it exists
require_once ("config.php");
// Make DB functions available
require_once ("db-functions.php");
$sitesettings = db_getsettings();

// Decide what to do based on GET mode
switch ($mode){
	case "shownet": 
		$subnet = urldecode($_GET['NetID']);
		include ("display-subnet.php");
		break;
	case "listnets":
		include ("list-subnets.php");
		break;
	case "addnet":
		include ("add-subnet.php");
		break;
	case "subnetadded":
		// This will give us $complete_subnet - ['NetID'] ['SNM'] and ['CIDR']
		$complete_subnet =  (split_cidr(urldecode($_POST['NetID'])));
	
		//$complete_subnet['range'][0] will be bottom low end of subnet, [1] will be high end
		$complete_subnet['range'] = subnet_low_high($complete_subnet['NetID'],$complete_subnet['CIDR']);
		
		$complete_subnet['scanint'] = $_POST['scanint'];
		echo_array ($complete_subnet);
		insert_subnet($complete_subnet);
		insert_ips($complete_subnet);
		if ($_POST['viewnew']){
			// If the view new checkbox was selected, take user to subnet's page
			$subnet = urldecode($complete_subnet['NetID']);
			include ("display-subnet.php");
		} else {
			// Otherwise, go back to the subnet list
			include ("list-subnets.php");
		}
		break;
	default:
		include("list-subnets.php");
		break;
}

?>